package de.gameduell.framework.queue {
	import fl.transitions.TweenEvent;
	
	import de.gameduell.framework.gui.animation.Tweenable;
	
	import flash.events.EventDispatcher;	

	/**
	 * @author ddoe
	 */
	public class TweenAction extends EventDispatcher implements IGDAction {
		private var tween:Tweenable;
		private var actionQueue:GDActionQueue;
		private var _description:String;

		public function TweenAction(aTween:Tweenable,invokeNow:Boolean = false,aDescription:String = "TweenAction") {
			tween = aTween;
			tween.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinished);
			_description = aDescription;
			actionQueue = GDActionQueue.getInstance();		
			if(invokeNow){
				invoke();
			}
		}
		
		public function compute():void {
			tween.start();
		}
		
		public function invoke():void {
			actionQueue.add(this);
		}
		
		public function onMotionFinished(event:TweenEvent):void{	
			dispatchEvent(new ActionEvent(ActionEvent.DONE));
		}
		
		public function get description():String {
			return _description;
		}
	}
}
